package util;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class MyBatisUtil {
    private static SqlSessionFactory sessionFactory;
    static {
        sessionFactory=new SqlSessionFactoryBuilder()
                .build(MyBatisUtil.class
                                  .getClassLoader()
                                  .getResourceAsStream("mybatis-config.xml"));
    }

    public static SqlSession getSession(){
        return sessionFactory.openSession();
    }

    public static void closeSession(SqlSession sqlSession){
        if(sqlSession!=null){
            sqlSession.close();
        }
    }
}
